﻿<phone:PhoneApplicationPage 
    x:Name="LoanEditView"
    x:Class="DebIt.View.LoanEdit"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Controls="clr-namespace:Phone7.Fx.Controls;assembly=Phone7.Fx"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:converters="clr-namespace:DebIt.Converter" mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <phone:PhoneApplicationPage.Resources>
        <converters:DateConverter x:Key="DateConverter"/>
    </phone:PhoneApplicationPage.Resources>

        <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <!--Pivot Control-->
        <controls:Pivot Title="{Binding LocalizedResources.appName, Source={StaticResource LocalizedStrings}}">
            <!--Pivot item details-->
            <controls:PivotItem Header="{Binding LocalizedResources.pi_title_loan_edit_details, Source={StaticResource LocalizedStrings}}">
                <ListBox >
                    <StackPanel Width="456"   DataContext="{Binding Loan}">
                        <TextBlock TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}" Text="{Binding LocalizedResources.st_tb_name, Source={StaticResource LocalizedStrings}}" Margin="8,0"/>
                        <TextBox TextWrapping="Wrap"  Margin="8,0" MaxLength="25" Text="{Binding Name, Mode=TwoWay}" InputScope="Text"/>
                        <TextBlock TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}" Text="{Binding LocalizedResources.st_tb_description, Source={StaticResource LocalizedStrings}}" Margin="8,0"/>
                        <TextBox TextWrapping="Wrap" Margin="8,0" MaxLength="200" Text="{Binding Description, Mode=TwoWay}" InputScope="Text"/>
                        <TextBlock TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}" Text="{Binding LocalizedResources.st_tb_sum, Source={StaticResource LocalizedStrings}}" Margin="8,0"/>
                        <StackPanel Orientation="Horizontal" Margin="8,0">
                            <TextBox TextWrapping="Wrap" Text="{Binding LoanValue, Mode=TwoWay}" IsReadOnly="True"/>
                            <TextBox TextWrapping="Wrap" Text="{Binding Currency, Mode=TwoWay}" RenderTransformOrigin="0,0" MaxLength="15" InputScope="Text"/>
                        </StackPanel>
                        <TextBlock TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}" Text="{Binding LocalizedResources.st_tb_loan_per_client, Source={StaticResource LocalizedStrings}}" Margin="8,0"/>
                        <StackPanel Orientation="Horizontal" Margin="8,0">
                            <TextBox TextWrapping="Wrap" Text="{Binding LoanPerClient, Mode=TwoWay}" IsReadOnly="True"/>
                            <TextBox TextWrapping="Wrap" Text="{Binding Currency, Mode=TwoWay}" RenderTransformOrigin="0,0" MaxLength="15" InputScope="Text"/>
                        </StackPanel>
                        <TextBlock TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}" Text="{Binding LocalizedResources.st_tb_date, Source={StaticResource LocalizedStrings}}" Margin="8,0"/>
                        <TextBox TextWrapping="Wrap" Text="{Binding TimeStamp, Converter={StaticResource DateConverter}, Mode=TwoWay}" Margin="8,0" IsReadOnly="True"/>
                    </StackPanel>
                </ListBox>
            </controls:PivotItem>

            <!--Pivot item loan items-->
            <controls:PivotItem Header="{Binding LocalizedResources.pi_title_loan_edit_loanitems, Source={StaticResource LocalizedStrings}}">
                <ListBox x:Name="lbli" ItemsSource="{Binding LoanItems}"  DataContext="{Binding Loan}">
                    <ListBox.ItemContainerStyle>
                        <Style TargetType="ListBoxItem">
                            <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
                        </Style>
                    </ListBox.ItemContainerStyle>
                    <ListBox.ItemTemplate>
                        <DataTemplate >
                            <Grid Height="222" VerticalAlignment="Top">
                                <Border x:Name="boMain" BorderBrush="{StaticResource PhoneForegroundBrush}"  BorderThickness="3" Margin="8">
                                    <Grid Margin="5,-3,5,17" Height="198">
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="27"/>
                                            <RowDefinition Height="72"/>
                                            <RowDefinition Height="27"/>
                                            <RowDefinition Height="139"/>
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition/>
                                            <ColumnDefinition Width="80"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock TextWrapping="Wrap" Text="{Binding Path=LocalizedResources.st_tb_li_description, Source={StaticResource LocalizedStrings}}" Grid.ColumnSpan="2" Style="{StaticResource PhoneTextNormalStyle}"/>
                                        <TextBox TextWrapping="Wrap" Text="{Binding Description, Mode=TwoWay}" InputScope="Text" MaxLength="25" Grid.ColumnSpan="2" d:LayoutOverrides="Height" Grid.Row="1"/>
                                        <TextBlock TextWrapping="Wrap" Text="{Binding Path=LocalizedResources.st_tb_li_value, Source={StaticResource LocalizedStrings}}" Grid.ColumnSpan="2" Grid.Row="2" Style="{StaticResource PhoneTextNormalStyle}"/>
                                        <TextBox TextWrapping="Wrap" Text="{Binding Value, Mode=TwoWay}" InputScope="Number" MaxLength="11" Grid.Row="3" d:LayoutOverrides="Height" Margin="0,0,0,67"/>
                                        <Button x:Name="btnDelete" BorderBrush="Transparent" Foreground="Transparent" BorderThickness="0" HorizontalAlignment="Right" Width="80" Grid.Column="1" Grid.Row="3" Margin="0,0,0,67"
                                                Command="{Binding ElementName=LoanEditView, Path=DataContext.RemoveLoanItemCommand}" CommandParameter="{Binding}">
                                            <Image x:Name="imgDelete" Source="../icons/dark/delete.png" Height="75" Width="75"  HorizontalAlignment="Center" VerticalAlignment="Center" Loaded="ImgDeleteLoaded">                                 
                                            </Image>
                                        </Button>
                                    </Grid>
                                </Border>
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </controls:PivotItem>

            <!--Pivot item friends-->
            <controls:PivotItem Header="{Binding LocalizedResources.pi_title_loan_edit_friends, Source={StaticResource LocalizedStrings}}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="80"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" MinHeight="80"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <ListBox ItemsSource="{Binding ClientLoanStates}" Grid.Row="1" Grid.ColumnSpan="2"  DataContext="{Binding Loan}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid Height="113" Width="456">
                                    <Border BorderBrush="{StaticResource PhoneForegroundBrush}"  BorderThickness="3" Margin="8,8,8,10">
                                        <Grid Margin="5,0,-3,-3">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition/>
                                                <ColumnDefinition Width="80"/>
                                            </Grid.ColumnDefinitions>
                                            <StackPanel>
                                                <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding Client.FirstName}"  FontSize="{StaticResource PhoneFontSizeLarge}" Height="42.5633316040039" Style="{StaticResource PhoneTextNormalStyle}"/>
                                                <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding Client.LastName}"  FontSize="{StaticResource PhoneFontSizeLarge}" Height="42.5633316040039" Style="{StaticResource PhoneTextNormalStyle}"/>
                                            </StackPanel>
                                            <Button x:Name="btnDelete" BorderBrush="Transparent" Foreground="Transparent" BorderThickness="0" HorizontalAlignment="Right" Width="80" Margin="0,8,0,17" 
                                                    d:LayoutOverrides="VerticalAlignment" Height="75" Grid.Column="1"
                                                    Command="{Binding ElementName=LoanEditView, Path=DataContext.RemoveClientCommand}" CommandParameter="{Binding}">
                                                <Image Source="../icons/dark/delete.png" Height="75" Width="75"  HorizontalAlignment="Center" VerticalAlignment="Center"  Loaded="ImgDeleteLoaded"/>
                                            </Button>
                                        </Grid>
                                    </Border>
                                </Grid>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                    <toolkit:ListPicker x:Name="lpClients" ItemsSource="{Binding Clients}"  Margin="12,8,0,8">
                        <toolkit:ListPicker.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding FirstName}" Margin="0,0,5,0"/>
                                    <TextBlock Text="{Binding LastName}" Margin="5,0,0,0" />
                                </StackPanel>
                            </DataTemplate>
                        </toolkit:ListPicker.ItemTemplate>
                        
                    </toolkit:ListPicker>
                    <Button BorderBrush="Transparent" Foreground="Transparent" BorderThickness="0" HorizontalAlignment="Right" Width="80" Grid.Column="1" Height="80" 
                            VerticalAlignment="Top" d:LayoutOverrides="GridBox" 
                            Command="{Binding AddClientCommand}" CommandParameter="{Binding Path=SelectedItem, ElementName=lpClients}">
                        <Image x:Name="imgAdd" Source="../icons/dark/add.png"
                						Height="75"
                						Width="75"  HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    </Button>
                </Grid>
            </controls:PivotItem>

        </controls:Pivot>
        <Controls:BindableApplicationBar IsVisible="True" IsMenuEnabled="True" x:Name="apMain" ItemsSource="{Binding}">
            <Controls:BindableApplicationBarIconButton IconUri="/icons/dark/check.png" Text="{Binding Path=LocalizedResources.st_pivot_accept, Source={StaticResource LocalizedStrings}}" Click="BindableApplicationBarIconButtonClick"/>
            <Controls:BindableApplicationBarMenuItem Text="{Binding LocalizedResources.na_new_loanitem, Source={StaticResource LocalizedStrings}}" Command="{Binding AddLoanItemCommand}" CommandParameter="{Binding Loan}"/> 
        </Controls:BindableApplicationBar>
    </Grid>


</phone:PhoneApplicationPage>